#ifndef __I386_UTIL_REG_H__
#define __I386_UTIL_REG_H__

#include "common/basictypes.h"
#include "common/code16gcc.h"

/* These functions are used to reference data in other segments. */
static inline u16 ds(void) {
  u16 seg;
  asm("movw %%ds,%0" : "=rm" (seg));
  return seg;
}

static inline void set_fs(u16 seg) {
  asm volatile("movw %0,%%fs" : : "rm" (seg));
}

static inline u16 fs(void) {
  u16 seg;
  asm volatile("movw %%fs,%0" : "=rm" (seg));
  return seg;
}

static inline void set_gs(u16 seg) {
  asm volatile("movw %0,%%gs" : : "rm" (seg));
}

static inline u16 gs(void) {
  u16 seg;
  asm volatile("movw %%gs,%0" : "=rm" (seg));
  return seg;
}

#endif  // __I386_UTIL_REG_H__
